package com.sskj.lib.bean;

import com.sskj.lib.R;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public enum CoinEnum implements Serializable {
    BTC(R.mipmap.lib_icon_btc, "BTC", 1),
    ETH(R.mipmap.lib_icon_eth, "ETH", 2),
    GNT(R.mipmap.lib_icon_gnt, "GNT"),
    MANA(R.mipmap.lib_icon_mana, "MANA"),
    OMG(R.mipmap.lib_icon_omg, "OMG"),
    PST(R.mipmap.lib_icon_pst, "PST"),
    ZRX(R.mipmap.lib_icon_zrx, "ZRX"),
    USDT(R.mipmap.lib_icon_usdt, "USDT"),
    CQTF(R.mipmap.lib_icon_cqtf, "CQTF"),
    BAT(R.mipmap.lib_icon_bat, "BAT"),
    EXLC(R.mipmap.lib_icon_exlc, "EXLC"),
    DEFAULT(R.mipmap.lib_icon_default, "DEFAULT"),
    ;


    private int res;
    private String code;
    private int id;
    private boolean isSelect = false;
    private static List<CoinEnum> coinEnums;
    public static CoinEnum coinEnum = BTC;


    CoinEnum(int res, String code) {
        this.res = res;
        this.code = code;
    }

    CoinEnum(int res, String code, int id) {
        this.res = res;
        this.code = code;
        this.id = id;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public boolean isSelect() {
        return isSelect;
    }

    public void setSelect(boolean select) {
        isSelect = select;
    }

    public int getRes() {
        return res;
    }

    public void setRes(int res) {
        this.res = res;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public static List<CoinEnum> list() {
        if (coinEnums == null) {
            coinEnums = new ArrayList<CoinEnum>();
            coinEnums.add(BTC);
            coinEnums.add(ETH);
            coinEnums.add(GNT);
            coinEnums.add(MANA);
            coinEnums.add(OMG);
            coinEnums.add(PST);
            coinEnums.add(ZRX);
            coinEnums.add(USDT);
            coinEnums.add(CQTF);
            coinEnums.add(BAT);
            coinEnums.add(EXLC);
        }
        return coinEnums;
    }

    /**
     * 根据币种返回实体，默认返回BTC
     *
     * @param code
     * @return
     */
    public static CoinEnum getByCode(String code) {
        for (CoinEnum coinEnum : list()) {
            if (coinEnum.code.contains(code.toUpperCase().replace("_", "/"))) {
                return coinEnum;
            }
        }
        return DEFAULT;
    }

}
